<template>
	<div v-if="row.actions.length>2">
		<a @click="handleClickMore(row.actions[0].name, row)">{{ row.actions ? row.actions[0].label : '' }}</a>
		<Divider type="vertical" />
		<Dropdown @on-click="(name) => handleClickMore(name, row)" transfer>
			<a>更多
				<Icon type="ios-arrow-down" />
			</a>
			<DropdownMenu slot="list">
				<template v-for="(item, i) in row.actions.slice(1)">
					<DropdownItem v-if="showBtn(item.label)" :key="i" :name="item.name">{{ item.label }}
					</DropdownItem>
				</template>
			</DropdownMenu>
		</Dropdown>
	</div>
	<div v-else>
		<a v-if="row.actions && showBtn('启停')" @click="handleClickMore(row.actions[0].name, row)">{{ row.actions[0].label }}</a>
		<Divider v-if="row.actions && row.actions.length>1" type="vertical" />
		<a v-if="row.actions && row.actions.length>1" @click="handleClickMore(row.actions[1].name, row)">{{
				row.actions[1].label }}</a>
	</div>
</template>
<script>
import { ApiRequest } from '@api/basePage';
import dynamictableactions from '@/mixins/dynamictableactions'; // 混入通用代码
import { mapGetters } from 'vuex';
import { getBtnsId } from '@/libs/btnsPermission';
export default {
  mixins: [dynamictableactions],
  data () {
    return {
      actions: []
    };
  },
  computed: {
    ...mapGetters('permissions/systemBtns', ['showBtn'])
  },
  created () {},
  methods: {
    handleClickMore (name, row) {
      if (name === 'Alert') {
        let obj = {}; // 动作的对象信息
        row.actions.forEach((item) => {
          if (name === item.name) {
            obj = item;
            return false;
          }
        });
        this.setTableRowData(row);
        let curBtnId = getBtnsId('启停');
        sessionStorage.setItem('buttonId', curBtnId);
        if (obj.handleType === 'disable') {
          // 禁用
          this.$Modal.confirm({
            title: '禁用属性',
            content: '确定禁用吗？',
            onOk: () => {
              let data = {
                uuid: row.uuid
              };
              // 开始请求商品列表
              ApiRequest(
                this.requestApi.stop.url + '?uuid=' + row.uuid,
                this.requestApi.stop.type,
                data
              ).then((res) => {
                this.$Message.success('禁用成功');
                this.actionsChange();
              });
            }
          });
        } else {
          // 启用
          this.$Modal.confirm({
            title: '启用属性',
            content: '确定启用吗？',
            onOk: () => {
              let data = {
                uuid: row.uuid
              };
              // 开始请求商品列表
              ApiRequest(
                this.requestApi.start.url + '?uuid=' + row.uuid,
                this.requestApi.start.type,
                data
              ).then((res) => {
                this.$Message.success('启用成功');
                this.actionsChange();
              });
            }
          });
        }
      } else {
        let obj = {}; // 动作的对象信息
        row.actions.forEach((item) => {
          if (name === item.name) {
            obj = item;
            return false;
          }
        });
        this.setTableRowData(row);
        if (obj.handleType === 'link') {
          // 操作类型为链接时，拼接参数跳转
          let jumpPath = this.jumpPath + obj.name;
          this.$router.push({
            path: jumpPath,
            query: { uuid: row.uuid, orderType: row.orderType }
          });
        } else {
          // 操作类型为弹窗时 打开弹窗
        }
      }
    }
  }
};
</script>
